package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.base.BaseController;
import com.shop.entity.ProductImage;
import com.shop.result.ResultVO;
import com.shop.service.ProductImageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/productImage")
public class ProductImageController extends BaseController {
    private final ProductImageService productImageService;
    @GetMapping("/listProductImage")
    public ResultVO<Object> listProductImage(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        PageInfo<ProductImage> pageInfo = productImageService.listProductImage(page, limit);
        return success(pageInfo);
    }
    @GetMapping("/listWithProductImage")
    public ResultVO<Object> listWithProductImage(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<ProductImage> pageInfo = productImageService.listWithProductImage(pageNum, pageSize);
        return success(pageInfo);
    }
    @GetMapping("/getProductImageById")
    public ResultVO<Object> getProductImageById(@RequestParam("id") Integer id) {
        List<ProductImage> productImage = productImageService.getProductImageById(id);
        return success(productImage);
    }
    @PostMapping("/addProductImage")
    public ResultVO<Object> addProductImage(@RequestBody ProductImage productImage) {
        productImageService.addProductImage(productImage);
        return success("添加成功");
    }
    @GetMapping("/deleteProductImage")
    public ResultVO<Object> deleteProductImage(@RequestParam("productImageId") Integer id) {
        productImageService.deleteProductImage(id);
        return success("删除成功");
    }

}
